package com.jeesite.modules.exam.orgselect.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.exam.orgselect.service.DcExamOrgSelectService;
import com.jeesite.modules.exam.socreResult.entity.DcSupExamOrgSelect;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;

/**
 * dc_sup_exam_org_selectController
 * @author xhc
 * @version 2022-08-01
 */
@Controller
@RequestMapping(value = "${adminPath}/orgselect/dcSupExamOrgSelect")
public class DcSupExamOrgSelectController extends BaseController {

	@Autowired
	private DcExamOrgSelectService dcExamOrgSelectService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupExamOrgSelect get(String id, boolean isNewRecord) {
		return dcExamOrgSelectService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequestMapping(value = {"list", ""})
	public String list(DcSupExamOrgSelect dcSupExamOrgSelect, Model model) {
		model.addAttribute("dcSupExamOrgSelect", dcSupExamOrgSelect);
		return "modules/exam/orgselect/dcSupExamOrgSelectList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupExamOrgSelect> listData(DcSupExamOrgSelect dcSupExamOrgSelect, HttpServletRequest request, HttpServletResponse response) {
		dcSupExamOrgSelect.setPage(new Page<>(request, response));
		dcSupExamOrgSelect.setOrgStatus("0");
		Page<DcSupExamOrgSelect> page = dcExamOrgSelectService.findPage(dcSupExamOrgSelect);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequestMapping(value = "form")
	public String form(DcSupExamOrgSelect dcSupExamOrgSelect, Model model) {
		model.addAttribute("dcSupExamOrgSelect", dcSupExamOrgSelect);
		return "modules/exam/orgselect/dcSupExamOrgSelectForm";
	}

	/**
	 * 查看编辑表单
	 */
	@RequestMapping(value = "formNew")
	public String formNew(DcSupExamOrgSelect dcSupExamOrgSelect, Model model) {
		model.addAttribute("dcSupExamOrgSelect", dcSupExamOrgSelect);
		return "modules/exam/orgselect/dcSupExamOrgSelectFormNew";
	}

	/**
	 * 保存数据
	 */
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DcSupExamOrgSelect dcSupExamOrgSelect) {
		dcExamOrgSelectService.save(dcSupExamOrgSelect);
		return renderResult(Global.TRUE, text("保存成功！"));
	}
	
	/**
	 * 停用数据
	 */
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DcSupExamOrgSelect dcSupExamOrgSelect) {
		dcSupExamOrgSelect.setStatus(DcSupExamOrgSelect.STATUS_DISABLE);
		dcExamOrgSelectService.updateStatus(dcSupExamOrgSelect);
		return renderResult(Global.TRUE, text("停用成功"));
	}
	
	/**
	 * 启用数据
	 */
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DcSupExamOrgSelect dcSupExamOrgSelect) {
		dcSupExamOrgSelect.setStatus(DcSupExamOrgSelect.STATUS_NORMAL);
		dcExamOrgSelectService.updateStatus(dcSupExamOrgSelect);
		return renderResult(Global.TRUE, text("启用成功"));
	}
	
	/**
	 * 删除数据
	 */
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DcSupExamOrgSelect dcSupExamOrgSelect) {
		dcSupExamOrgSelect.setOrgStatus("1");
		dcExamOrgSelectService.update(dcSupExamOrgSelect);
		return renderResult(Global.TRUE, text("删除成功！"));
	}
	
}